'''
author:mzy
time:10:57
date:2022/8/24
'''
# import requests
# param = {"wd":"mzy"}
# resp = requests.get("https://www.baidu.com/s?",param)
# print(resp.text)


# 使用requests库session机制，实现 tpshop前台用户注册，并注册账号成功
# post /Home/User/reg.html
# Content-Type: application/x-www-form-urlencoded; charset=UTF-8
# scene=1&username=13548403728&verify_code=8888&password=1234567890&password2=123456789&invite=17727163772

# resp_v = requests.get(url="http://127.0.0.1/index.php?m=Home&c=User&a=verify&r=0.7328677362022877")
# print(resp_v)
# my_cookies = resp_v.cookies
# resp = requests.post(url="http://127.0.0.1/index.php?m=Home&c=User&a=do_login&t=0.15230652936282052",
#                      data={"username":"13548403728","password":"1234567890","verify_code":"8888"},
#                      cookies=my_cookies)

# resp = requests.post(url="http://127.0.0.1/Home/User/reg.html",
#                      headers={"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"},
#                      data={"scene":"1","username":"13548403728","verify_code":"8888","password":"1234567890","password2":"1234567890"})
# session = requests.session()
# resp_v = session.get(url="http://127.0.0.1/index.php?m=Home&c=User&a=verify&type=user_reg&r=0.030215623215508858")
# resp = session.post(url="http://127.0.0.1/Home/User/reg.html",
#                      headers={"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"},
#                      data={"scene":"1","username":"13578963456","verify_code":"8888","password":"1234567890","password2":"1234567890"})
# print(resp.json())


# 使用unittest框架，结合requests库，在框架中完成tpshop登录接口测试，添加 “登录成功” 断言。
import json

# def file_poration():
    #     data = [{"username":"13548403728","password":"1234567890","verify_code":"8888"},
    #           {"username":"13578962456","password":"1234567890","verify_code":"8888"},
    #           {"username":"13548403628","password":"1234567890","verify_code":"8888"}
    #         ]


#     data = [{"scene":"1","username":"13578963456","verify_code":"8888","password":"1234567890","password2":"1234567890"},
#             {"scene":"1","username":"13578963556","verify_code":"8888","password":"1234567890","password2":"1234567890"},
#             {"scene":"1","username":"13578963256","verify_code":"8888","password":"1234567890","password2":"1234567890"},
#             {"scene":"1","username":"13578963656","verify_code":"8888","password":"1234567890","password2":"1234567890"}]
#     with open("regiterdata.json",'w',encoding="utf-8") as f:
#         json.dump(data,f,ensure_ascii=False, indent=2)
# file_poration()

import unittest
from parameterized import parameterized
from request.methods import req_methods
from htmltestreport import HTMLTestReport

def start():
    with open("data.json",'r',encoding="utf-8") as f:
        b = json.load(f)
    # print(b)
    #
    class TestRegistered(unittest.TestCase):
        @parameterized.expand(b)
        def testregistered(self,u,p,c,d):
            # print("u={} p={} c={}".format(u,p,c))
            result = req_methods(u,p,c)
            print(result)
            self.assertEqual(d,result)

    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(TestRegistered))
    my_runner = HTMLTestReport("./LoginReport.html","登录测试报告")
    my_runner.run(suite)

start()





